#include "../include/MarketReport.h"
#include <iostream>



    CMarketReport::CMarketReport(void){}

	CMarketReport::CMarketReport(const std::string & configFile, const std::string & eventFile,
		int firstId,  int secondId):mConfigFile(configFile),mEventFile(eventFile),
		mFirstId(firstId),mSecondId(secondId){}

	CMarketReport::~CMarketReport(void){}



	bool CMarketReport::reportUser(int id, const std::string & name,
		const unitContainer & energyUnits, const std::string & stime) const{
			std::cout <<  std::endl << colorLinux(GREEN)<<
				"***User Report***" << std::endl <<
				stime << std::endl <<
				"ID: " << id << std::endl <<
				"Name: " << name << std::endl <<
				"Energy units: ";
			printUnits(energyUnits);
			std::cout << std::endl << colorLinux(BRIGHT_WHITE);
			return true;

	}

	bool CMarketReport::reportUser(int id, const std::string & name,
		const unitContainer & energyUnits, const Poco::DateTime & time) const{
			reportUser(id, name, energyUnits, toStr(time));
			return true;
	}


	bool CMarketReport::reportEnergy(valueContainer * energyValue, const std::string & stime) const{
			std::cout <<  std::endl << colorLinux(RED) <<
				"***Energy Report***" << std::endl <<
				stime << std::endl <<
				"Energy value: ";
			printValues(*energyValue);
			std::cout << std::endl << colorLinux(BRIGHT_WHITE);
			return true;

	}

	bool CMarketReport::reportEnergy(valueContainer * energyValue, const Poco::DateTime & time) const{
			reportEnergy(energyValue, toStr(time));
			return true;
	}


	bool CMarketReport::reportProfit(int id, const std::string & name, double profit, const std::string & stime) const{
		    std::cout <<   std::endl << colorLinux(YELLOW) <<
				"***Profit Report***" << std::endl <<
				stime << std::endl <<
				"User ID: " << id << std::endl <<
				"User name: " << name << std::endl <<
				"Profit: " << profit <<std::endl ;
			std::cout << std::endl << colorLinux(BRIGHT_WHITE);
			return true;
	}

	bool CMarketReport::reportProfit(int id, const std::string & name, double profit, const Poco::DateTime & time) const{
		reportProfit(id, name, profit, toStr(time));
		return true;
	}

	bool CMarketReport::reportActivity(const std::string & name, const unitContainer & produced,
		const unitContainer & consumed, const std::string & stime) const{
			std::cout  << std::endl << colorLinux(BLUE) <<
				"***Activity Report***" << std::endl <<
				stime << std::endl <<
				"User name: " << name << std::endl <<
				"Produced energy: " ;
			printUnits(produced);
			std::cout << std::endl<< "Consumed energy: " ;
			printUnits(consumed);
			std::cout << std::endl << colorLinux(BRIGHT_WHITE);
			return true;
	}


	bool CMarketReport::reportActivity(const std::string & name, const unitContainer & produced,
		const unitContainer & consumed, const Poco::DateTime & time) const{
			reportActivity(name,produced,consumed,toStr(time));
			return true;
	}




	bool CMarketReport::reportAccount(int userId, const std::string & userName, double amount,
		const std::string & stime) const{
		   std::cout << std::endl << colorLinux(CYAN) <<
				"***Account Report***" << std::endl <<
				stime << std::endl <<
				"User ID: " << userId << std::endl <<
				"User name: " << userName << std::endl <<
				"Amount: " << amount << std::endl;
		   std::cout << std::endl << colorLinux(BRIGHT_WHITE);
	       return true;
	}

	bool CMarketReport::reportAccount(int userId, const std::string & userName, double amount,
		const Poco::DateTime & time) const{
			reportAccount(userId, userName, amount, toStr(time));
			return true;
	}





	std::string CMarketReport::toStr(Poco::DateTime time) const{
            std::ostringstream ostr;
			std::string sTime;
			ostr << time.day() << "/" << time.month() << "/" << time.year();
			sTime = ostr.str();
			return sTime;
	}





	void CMarketReport::printUnits(unitContainer units) const{
		std::cout <<  "Oil: " << units.oil <<
			          "  Gas: " << units.gas <<
					  "  Coal: "<< units.coal<< std::endl <<
					  "  Sun: " << units.sun <<
					  "  Wind: "<< units.wind<<
					  "  Smile: "<<units.smile<<
					  "  Hug: " << units.hug  << std::endl;
	}
	void CMarketReport::printValues(valueContainer values) const{
		std::cout <<  "  Oil: " << values.oil <<
			          "  Gas: " << values.gas <<
					  "  Coal: "<< values.coal<< std::endl <<
					  "  Sun: " << values.sun <<
					  "  Wind: "<< values.wind<<
					  "  Smile: "<<values.smile<<
					  "  Hug: " << values.hug <<  std::endl;
	}

